package com.zlzsy.app.base.ui

import android.graphics.drawable.Drawable
import android.support.annotation.ColorInt
import android.support.annotation.ColorRes
import android.support.annotation.DrawableRes
import android.support.v4.app.Fragment
import android.view.View

/**
 * Created by niantuo on 2017/11/6.
 * ui的扩展方法
 */
/**
 * Created by niantuo on 2017/10/24.
 * 扩展view的函数
 */

fun View.dp2Px(dp: Int): Int {
    val scale = context.resources.displayMetrics.density
    return (dp * scale + 0.5f).toInt()
}


/**
 * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
 */
fun View.px2dip(pxValue: Float): Int {
    val scale = context.resources.displayMetrics.density
    return (pxValue / scale + 0.5f).toInt()
}

fun Fragment.getDrawable(@DrawableRes id: Int): Drawable {
    return resources.getDrawable(id)
}

@ColorInt
fun Fragment.getColor(@ColorRes id: Int): Int {
    return resources.getColor(id)
}
